/*
 * Copyright By ZATI
 * Copyright By 3a3c88295d37870dfd3b25056092d1a9209824b256c341f2cdc296437f671617
 * All rights reserved.
 *
 * If you are not the intended user, you are hereby notified that any use, disclosure, copying, printing, forwarding or
 * dissemination of this property is strictly prohibited. If you have got this file in error, delete it from your system.
 */

package cn.wzc.crystal.iam.controller;

import cn.wzc.crystal.iam.dto.IamUserDto;
import cn.wzc.crystal.iam.manager.IamUserManager;
import cn.wzc.crystal.platform.golbal.GlobalErrorCode;
import cn.wzc.crystal.platform.support.ApiResult;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
public class UserController {

	private final IamUserManager userManager;

	@PostMapping
	@PreAuthorize("hasRole('ADMIN')")
	public ApiResult create(@RequestBody @Valid IamUserDto userDto) {
		final Long userId = userManager.saveUser(userDto);
		return ApiResult.of(GlobalErrorCode.SUCCESSFUL, userId);
	}


}
